package com.ggs.starbug.thread;

import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang.math.RandomUtils;

import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @Author lianghaohui
 * @Date 2021/12/24 11:56
 * @Description
 */
@Data
@Builder
public class ThreadEntity {

    private int num;

    private int price;

    public int countPrice() {
        price = RandomUtils.nextInt();
        try {
            System.out.println("start" + num);
            // 随机等待1~10秒
            Thread.sleep(RandomUtils.nextInt(new Random(1), 10) * 1000);
            System.out.println("end" + num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return price;
    }

    public static void main(String[] args) {
        List<ThreadEntity> list = IntStream.range(0, 10).mapToObj(x -> ThreadEntity.builder().num(x).build()).collect(Collectors.toList());
    }

}
